package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.web.CategoryVo;
import com.atguigu.gmall.web.feign.CategoryFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: IndexController
 * Package: com.atguigu.gmall.web.controller
 * Description:首页跳转
 *
 * @Author ltystart
 * @Create 2025/8/22 16:27
 * @Version 1.0
 */
@Controller
public class IndexController {
    @Autowired
    private CategoryFeignClient categoryFeignClient;

    /**
     * 跳转首页
     * @return
     */
    @GetMapping("/")
    public String indexPage(Model model){
        //RPC商品服务，得到结果
        List<CategoryVo> list =new ArrayList<>();
        Result<List<CategoryVo>> categorys = categoryFeignClient.getCategorys();
        List<CategoryVo> data = categorys.getData();
        model.addAttribute("list", data);
        return "index/index";
    }
}
